package day01;

import org.apache.commons.io.FileUtils;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

class FileUtils2{
    public static void copyUrlFile(File srcFile,File targetFile) throws IOException {
//        BufferedInputStream bin = new BufferedInputStream(
//                new FileInputStream(srcFile)
//        );
//        BufferedOutputStream bout = new BufferedOutputStream(
//                new FileOutputStream(targetFile)
//        );
//        byte[] buff = new byte[1024];
//        int len = -1;
//        System.out.println("开始");
//        while((len=bin.read(buff))>0) {
//            bout.write(buff,0,len);
//            bout.flush();
//        }
//        System.out.println("结束");
//        bin.close();
//        bout.close();
        FileUtils.copyURLToFile(new URL("https://tse3-mm.cn.bing.net/th/id/OIP-C.L_Qp_UQnBWQBRHqEDGtf6AHaE7?w=291&h=194&c=7&r=0&o=5&dpr=1.3&pid=1.7"),
                targetFile);
    }
}

public class BufferInputStreamDemo01 {
    public static void main(String[] args) throws URISyntaxException, IOException {
//        File srcFile = new File(new URI("https://cn.bing.com/images/search?view=detailV2&ccid=L%2fQp%2fUQn&id=4B45838EE8EFEB678EAE6071787DC8655806A6B3&thid=OIP.L_Qp_UQnBWQBRHqEDGtf6AHaE7&mediaurl=https%3a%2f%2fimg95.699pic.com%2fphoto%2f60017%2f2391.jpg_wh860.jpg&exph=573&expw=860&q=tupian&simid=608049361613584936&FORM=IRPRST&ck=C19AA73EF42120E9D98A18470CEAE827&selectedIndex=0&itb=0&idpp=overlayview&ajaxhist=0&ajaxserp=0"));
        File srcFile = new File(new URI(""));
        File targetFile = new File("D:\\1\\img-2.jpeg");
        FileUtils2.copyUrlFile(srcFile,targetFile);
    }
}
